/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package courseScheduler;


/**
 *
 * @author david
 */
public class Block {
    int id;
    int timeID;
    int roomID;

    java.sql.PreparedStatement getBlockStatement;
    java.sql.PreparedStatement setBlockStatement;
    java.sql.PreparedStatement insertBlockStatement;

    java.sql.Connection conn;

    Block(int newTime, int newroom) {
        timeID = newTime;
        roomID = newroom;
    }

    Block(java.sql.Connection newConn, int newID){

    }

    public void setBlock(){

    }

    public void insertBlock(){

    }

    private void prepareGetStatement() throws java.sql.SQLException{
        getBlockStatement = conn.prepareStatement("SELECT date_time_id,room_id FROM block WHERE id = ?");
    }

    private void prepareSetStatemnt() throws java.sql.SQLException{
        setBlockStatement = conn.prepareStatement("UPDATE block date_time_id = " + timeID + ",room_id = " + roomID + " WHERE id = ?;");
    }

    private void prepareInsertStatement() throws java.sql.SQLException{
        insertBlockStatement = conn.prepareStatement("INSERT INTO bloct (date_time_id,room_id) VALUES (" + timeID + "," + roomID + ");");
    }

    public int getID(){
        return id;
    }

    public final void setID(int newID){
        id = newID;
    }

    public int getTime(){
        return timeID;
    }

    public final void setTime(int newTime){
        timeID = newTime;
    }

    public int getRoom(){
        return roomID;
    }

    public final void setRoom(int newRoom){
        roomID = newRoom;
    }

    public static int getID(java.sql.Connection newConn, int roomID, int timeID) throws java.sql.SQLException{
        java.sql.Statement stmnt = newConn.createStatement();
        java.sql.ResultSet rs = stmnt.executeQuery("SELECT id FROM block WHERE room_id = " + roomID + " AND date_time_id = " + timeID + ";");
        rs.first();
        return rs.getInt(1);
    }
}
